﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LordJS.Models;
using LordJS.Extensions;

namespace LordJS.Controllers
{
    public class EmployeeController : Controller
    {
        private static List<Employee> GetEmployees()
        {
            List<Employee> employees = new List<Employee>();
            employees.Add(new Employee { Id = 1, Name = "David", Age = 33, Title = "Senior Developer" });
            employees.Add(new Employee { Id = 2, Name = "Lynn", Age = 31, Title = "Translater" });
            employees.Add(new Employee { Id = 3, Name = "Mary", Age = 28, Title = "Business Analyst" });
            employees.Add(new Employee { Id = 4, Name = "Peter", Age = 25, Title = "Developer" });

            return employees;
        }

        public ActionResult MockEmployees()
        {
            IList<Employee> employees = GetEmployees();

            return Json(employees, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public string EmployeeList()
        {
            List<Employee> employees = GetEmployees();

            return JsonUtil.SerializeObject<List<Employee>>(employees);
        }

        [HttpPost]
        public string GetXmlData()
        {
            List<Employee> employees = GetEmployees();

            string xmlData = XmlSerializeUtil.SerializeObjectToXml<List<Employee>>(employees);

            return xmlData;
        }
    }
}
